/*本模块功能:学生选课
        编写者:朱光曜
        编写时间:2017.11.20
        editor：yxj
        20180515

        */
$(function(){
	var Alert1 = new Alert;
	var loading1 = new Loading();//监控全局ajax添加loading
	loading1.init();
    $(document).ajaxSend(function(){
		loading1.show();
		
		});
	$(document).ajaxStop(function(){
		loading1.hide();
		
		});
	var index={
		init:function(){
			this.bind();
		},
		bind:function(){
			var self=this;
			self.load();
			$(document).off("click","#sex input").on("click","#sex input",function(){
               
				$(this).next("label").addClass("checked").siblings("label").removeClass("checked");
			});
            $(document).off("click","#sexs input").on("click","#sexs input",function(){

                $(this).next("label").addClass("checked").siblings("label").removeClass("checked");
            });
			$(".preservation").off("click").click(function(){//点击提交
				var saveParam=$("#sex .checked").attr("num");
                var saveParams=$("#sexs .checked").attr("num");
				self.delivery(saveParam,saveParams);
			});
			
		},
		load:function(){//加载页面基本信息
			var parameter={};
			$.ajax({
				type: "post",
				url: "skipParamMana",
				async: true,
				data: {
					"jsonStr": JSON.stringify(parameter)
				},
			
				success: function(msg) {
			
					var msgNew = JSON.parse(msg);
					
					if(msgNew.selectCourseMark==1){
						$("#sex label").eq(0).addClass("checked").siblings("label").removeClass("checked");
					}
					if(msgNew.selectCourseMark==2){
						$("#sex label").eq(1).addClass("checked").siblings("label").removeClass("checked");
					}
                    if(msgNew.selectAnswerMark==1){
                        $("#sexs label").eq(0).addClass("checked").siblings("label").removeClass("checked");
                    }
                    if(msgNew.selectAnswerMark==2){
                        $("#sexs label").eq(1).addClass("checked").siblings("label").removeClass("checked");
                    }
					
			
				},
				error: function(data, status, xhr) {
					var json = JSON.stringify({
						"pageName": "error"
				    });
					window.location.href = "skipPage?jsonStr=" + json;

				}
			});
		},
		delivery:function(saveParam,saveParams){//点击提交
			var $self=this;
			var parameter={
				"selectCourseMark":parseInt(saveParam),
				"selectAnswerMark":parseInt(saveParams)
			};
		
			$.ajax({
				type: "post",
				url: "saveParam",
				async: true,
				data: {
					"jsonStr": JSON.stringify(parameter)
				},
			
				success: function(msg) {
			
					var msgNew = JSON.parse(msg);
					var self = $self;
				
					if(msgNew.result == "success") {
						self.alert1("保存成功");
			
					} else {
						//self.alert1(msgNew.failMsg);
						if(msgNew.failMsg){
							self.alert1(msgNew.failMsg);
						}else{
							self.alert1("保存失败");
						}

					}
			
				},
				error: function(data, status, xhr) {
					var json = JSON.stringify({
						"pageName": "error"
				    });
					window.location.href = "skipPage?jsonStr=" + json;

				}
			});
		},
		alert1: function(content1) { //confirm提示

			Alert1.contenthead = "提示";
			Alert1.content = content1;

			Alert1.success = function() {
				window.location.reload();
				Alert1.hide();
			};

			Alert1.init();
			Alert1.show();
		}
		
	};
	index.init();
});
